﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
using CPPEI.UMP.Proxy;

namespace CPPEI.ETL.Infrastructure.SMS
{
    public class SMSHelper
    {
        #region 初始化
        private string PostUrl { get; set; }
        // 接口帐号, 请换成你的帐号, 格式为 1001@+ 登录帐号 已绑定
        private string Account { get; set; }
        // 接口密钥, 请换成你的帐号对应的接口密钥  既定密码 账号分配密码
        private string AuthKey { get; set; }
        // 通道组编号, 请换成你的帐号可以使用的通道组编号 -- 测试账号，测试通道为手机号通道
        private int CgId { get; set; }
        public SMSHelper(string postUrl = "", string account = "", string authKey = "", int cgId = 0)
        {
            this.PostUrl = postUrl;
            this.Account = account;
            this.AuthKey = authKey;
            this.CgId = cgId;
        }

        public SMSHelper()
        {
            PostUrl = ConfigurationManager.AppSettings["SMS.PostUrl"];
            Account = ConfigurationManager.AppSettings["SMS.Account"];
            AuthKey = ConfigurationManager.AppSettings["SMS.AuthKey"];
            CgId = Convert.ToInt32(ConfigurationManager.AppSettings["SMS.CgId"]);
        }
        #endregion

        #region 群发接口
        /************************************************************************/
        /* 群发接口
        /* 建议1000个及以内的手机号码，,超过系统上限将会返回参数错误
        /************************************************************************/
        /// <summary>
        /// 群发接口
        /// </summary>
        /// <param name="from">标题 </param>
        /// <param name="content">内容 </param>
        /// <param name="mobile">手机号码 建议1000个及以内的手机号码，,超过系统上限将会返回参数错误</param>
        /// <returns></returns>
        public SMSResponse SendOnce(string from, string content, params string[] mobile)
        {

            var result = UMPProxy.SendMSG(from, mobile, content);
            return new SMSResponse()
            {
                IsSuccess = result.IsSuccess,
                Data = new SMSResponseResultData() { BatchId = result.Data.BatchId },
                ErrorCode = result.ErrorCode,
                Message = result.Message
            };
        }
        #endregion

    }
}
